package main

import "fmt"

// Animal 就近原则~
type Animal struct {
	Name  string
	Color string
}

type Cat struct {
	Animal //继承
	Color  string
}

func (a *Animal) sayColor() {
	fmt.Println("Animal:my Color is :", (*a).Color)
}

func (c *Cat) sayColor() {
	fmt.Println("Cat:my Color is :", (*c).Color)
}

func main() {
	fmt.Println("-----------两种方式使用-----------")
	var c *Cat = new(Cat)
	(*c).Animal.Name = "tom"
	(*c).Animal.Color = "blue"
	(*c).Animal.sayColor() //Animal:my Color is : blue
	fmt.Println(*c)        //{{tom blue} }

	var c1 *Cat = new(Cat)
	(*c1).Name = "jack"
	(*c1).Color = "black"
	(*c1).sayColor() //Cat:my Color is : black
	fmt.Println(*c1) //{{jack } black}

}
